#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

static void my_exit1(void);
static void my_exit2(void);

int main(void)
{
	if (atexit(my_exit2) != 0)
		perror("can't register my_exit2");
	if (atexit(my_exit1) != 0)
		perror("can't register my_exit1");
	if (atexit(my_exit1) != 0)
		perror("can't register my_exit1");

	printf("main is done\n");
	//_exit(0); //直接退出，不会清理空间
	//exit(0); //调用exit函数逆序调用注册的函数
	//return (0);//退出同样有exit调用注册的函数
	/*exit会逆序执行注册的函数*/
}

static void my_exit1(void)
{
	printf("first exit handler\n");
}
static void my_exit2(void)
{
	printf("second exit handler\n");
}

